package com.example.cr.insect.controller.admin;

import com.example.cr.common.response.PageResponse;
import com.example.cr.common.response.R;
import com.example.cr.insect.request.PreventionPlanListRequest;
import com.example.cr.insect.response.PreventionPlanResponse;
import com.example.cr.insect.service.PreventionPlanService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.cr.insect.request.PreventionPlanRequest;
import java.util.List;

@RestController
@RequestMapping("admin/prevention-plan")
public class PreventionPlanAdminController {
    @Autowired
    PreventionPlanService preventionPlanService;

    @GetMapping("list")
    public R<PageResponse<PreventionPlanResponse>> list(@Valid PreventionPlanListRequest request) {
        PageResponse<PreventionPlanResponse> list = preventionPlanService.list(request);
        return R.ok(list);
    }
    @PostMapping("save")
    public R<Object> save(@Valid @RequestBody PreventionPlanRequest request) {
        preventionPlanService.save(request);
        return R.ok();
    }

    @DeleteMapping("delete")
    public R<Integer> delete(@RequestBody List<Long> ids) {
        int result = preventionPlanService.deleteBatch(ids);
        return R.ok(result);
    }
}
